//
//  PersonViewController.m
//  嘀嘀拍
//
//  Created by wangjia_01 on 16/2/25.
//  Copyright © 2016年 wangjia_01. All rights reserved.
//

#import "PersonViewController.h"




@interface PersonViewController ()
<UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIGestureRecognizerDelegate>

//个人中心参数
@property (weak, nonatomic) IBOutlet UILabel *userName;
@property (weak, nonatomic) IBOutlet UIButton *userPhoto;
//视频数
@property (weak, nonatomic) IBOutlet UILabel *label1;
//转发数
@property (weak, nonatomic) IBOutlet UILabel *label2;
//关注数
@property (weak, nonatomic) IBOutlet UILabel *label3;
//粉丝数
@property (weak, nonatomic) IBOutlet UILabel *label4;
//赞数
@property (weak, nonatomic) IBOutlet UILabel *label5;
//@我的数
@property (weak, nonatomic) IBOutlet UILabel *label6;
//评论数
@property (weak, nonatomic) IBOutlet UILabel *label7;
//私信数
@property (weak, nonatomic) IBOutlet UILabel *label8;
@end

@implementation PersonViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    [isLogin Fillet:_userPhoto :120];
    [self getPersonData];
    // Do any additional setup after loading the view.
}

- (void)getPersonData
{   WC;
    [httpRequest getPersonInfoComplement:^(NSDictionary *dic) {
        DLog(@"%@",dic);
        
        if ([dic[@"code"] integerValue]==200) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
              
                NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:[isLogin isHttpHeader:[isLogin isNull:dic[@"data"][@"avatar"]]]]];
               // [weakSelf.userPhoto setImageWithURL:[NSURL URLWithString:[isLogin isNull:dic[@"data"][@"avatar"]]]];
                [weakSelf.userPhoto setImage:[UIImage imageWithData:data] forState:UIControlStateNormal];
            });
            
            weakSelf.userName.text=[isLogin isNull:dic[@"data"][@"user_name"]];
            weakSelf.label1.text=[isLogin isNull:dic[@"data"][@"question_count"]];
            //暂时不写
            weakSelf.label2.text=[isLogin isNull:dic[@"data"][@"share_count"]];
            weakSelf.label3.text=[isLogin isNull:dic[@"data"][@"friend_count"]];
            weakSelf.label4.text=[isLogin isNull:dic[@"data"][@"fans_count"]];
            weakSelf.label5.text=[isLogin isNull:dic[@"data"][@"thanks_count"]];
            //暂时不写
            weakSelf.label6.text=[isLogin isNull:dic[@"data"][@"at_count"]];
            weakSelf.label7.text=[isLogin isNull:dic[@"data"][@"answer_count"]];
            weakSelf.label8.text=[isLogin isNull:dic[@"data"][@"inbox_recv"]];
        }else
        {
        
            [SVProgressHUD showErrorWithStatus:dic[@"message"]];
        }
        
    }];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)clickChangeImg:(id)sender {
    UIActionSheet *as=[[UIActionSheet alloc]initWithTitle:@"上传头像" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"马上照一张" otherButtonTitles:@"从相册中选择一张", nil ];
    as.actionSheetStyle=2;
    [as showInView:[[[UIApplication sharedApplication] delegate] window]];
    
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
    switch (buttonIndex) {
        case 0:
        {
            UIImagePickerController *imgPicker=[[UIImagePickerController alloc]init];
            [imgPicker setSourceType:UIImagePickerControllerSourceTypeCamera];
            imgPicker.delegate = self;
            [imgPicker setAllowsEditing:YES];
            [self presentViewController:imgPicker animated:YES completion:^{
            }];
        }
            //照一张
            break;
        case 1:
            //搞一张
        {
            UIImagePickerController *imgPicker=[[UIImagePickerController alloc]init];
            [imgPicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
            [imgPicker setDelegate:self];
            [imgPicker setAllowsEditing:YES];
            [self presentViewController:imgPicker animated:YES completion:^{
            }];
            break;
        }
        default:
            break;
    }
    
    
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    
    [picker dismissViewControllerAnimated:YES completion:nil];
    UIImage  *userHea;
    userHea=[info objectForKey:@"UIImagePickerControllerEditedImage"];
    
    NSData *data = UIImageJPEGRepresentation(userHea, 0.01);
    
    
    [httpRequest  updateUserPhotoBy:data Complement:^(NSDictionary *dic) {
        
        
        if ([dic[@"code"] integerValue]==200) {
             [_userPhoto setImage:userHea forState:UIControlStateNormal];
        }
    }];

    
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
